package com.itrus.cert;

import com.itrus.cert.asn1.DERTags;
import com.itrus.util.CertUtils;
import com.itrus.util.DERUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Stack;

public class ItrusCRL
  implements DERTags
{
  private static final int[] prime_list = { 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741 };
  private int count = 0;
  private boolean debug = true;
  private int[] indexMap = null;
  private byte[] issuerDNBytes = null;
  private Date nextUpdate = null;
  private int pos = 0;
  private byte[] revokedCertSNs = null;
  private Date thisUpdate = null;
  private int version = 0;

  public ItrusCRL(InputStream paramInputStream)
    throws IOException
  {
    init(paramInputStream);
  }

  private boolean findSerialNumber(BigInteger paramBigInteger)
  {
    if (this.indexMap == null)
      return false;
    this.indexMap.length;
    byte[] arrayOfByte = paramBigInteger.toByteArray();
    int i = this.indexMap.length;
    int j = paramBigInteger.mod(DERUtils.HexStringToBigInteger(Integer.toHexString(i))).intValue();
    if (this.indexMap[j] == -1)
      return false;
    if (isSerialNumberExist(arrayOfByte, this.indexMap[j]))
      return true;
    for (int k = 1; ; k++)
    {
      if (k > 20)
        return false;
      j += (k << 0) % i;
      if (j >= i)
        j -= i;
      if (this.indexMap[j] == -1)
        return false;
      if (isSerialNumberExist(arrayOfByte, this.indexMap[j]))
        return true;
    }
  }

  private void init(InputStream paramInputStream)
    throws IOException
  {
    int i = 0;
    ((byte[])null);
    int j = 0;
    int k = 0;
    int m = 0;
    int n = 0;
    int i1 = 0;
    int i2 = 0;
    Stack localStack = new Stack();
    int i3 = 0;
    int i4 = 1;
    this.pos = 0;
    label54: int i8;
    int i14;
    label81: int i10;
    if (this.pos > j)
      if (this.debug)
      {
        int[] arrayOfInt = this.indexMap;
        i8 = 0;
        int i9 = 0;
        if (arrayOfInt != null)
        {
          i14 = 0;
          if (i14 < this.indexMap.length)
            break label1076;
          i9 = this.indexMap.length;
        }
        System.out.println("Array:数组大小=" + i9 + ", 吊销证书=" + this.count + ", 占用位置=" + i8 + ", 少了=" + (this.count - i8) + ", 冲突次数=" + i3);
        if (this.revokedCertSNs != null)
        {
          System.out.println("序列号存储空间=" + this.revokedCertSNs.length);
          i10 = 0;
        }
      }
    label651: label788: label1046: label1048: label1074: label1076: for (int i11 = this.revokedCertSNs[0]; ; i11 = this.revokedCertSNs[i10])
    {
      int i12 = this.revokedCertSNs.length;
      if ((i10 >= i12) || (i11 == 0));
      label326: label343: label630: int i13;
      label834: label848: label851: 
      do
      {
        return;
        int i5 = paramInputStream.read();
        this.pos = (1 + this.pos);
        if ((this.pos == 0) && (i5 != 48))
          throw new IOException("CRL format error, should be DER binary");
        int i6 = readLength(paramInputStream);
        if (i5 == 48)
        {
          i2++;
          if (i2 == 4)
          {
            this.issuerDNBytes = new byte[i6];
            paramInputStream.read(this.issuerDNBytes, 0, i6);
            this.pos = (i6 + this.pos);
            if ((this.pos != j) || (localStack.size() <= 0))
              break label1046;
            if (localStack.size() != 0)
              break label1048;
          }
        }
        for (int i7 = 1; ; i7 = 0)
        {
          if (i7 != 0)
            break label1074;
          Integer localInteger1 = new Integer(j);
          localStack.push(localInteger1);
          break;
          if (i2 == 5)
          {
            k = i6;
            j = i6 + this.pos;
            Integer localInteger5 = new Integer(j);
            localStack.push(localInteger5);
            break label326;
          }
          if (i2 == 6)
          {
            m = i6;
            j = i6 + this.pos;
            Integer localInteger4 = new Integer(j);
            localStack.push(localInteger4);
            break label326;
          }
          j = i6 + this.pos;
          Integer localInteger3 = new Integer(j);
          localStack.push(localInteger3);
          break label326;
          if (i5 == 49)
          {
            j = i6 + this.pos;
            Integer localInteger2 = new Integer(j);
            localStack.push(localInteger2);
            break label326;
          }
          if (i5 == 2)
          {
            byte[] arrayOfByte3 = new byte[i6];
            paramInputStream.read(arrayOfByte3, 0, i6);
            this.pos = (i6 + this.pos);
            if ((i6 == 1) && (i2 == 2))
            {
              this.version = arrayOfByte3[0];
              break label326;
            }
            int i18;
            int i19;
            int i16;
            if ((this.revokedCertSNs == null) && (i4 != 0))
            {
              if (arrayOfByte3[0] == 0)
              {
                i18 = k / (m - 1);
                this.revokedCertSNs = new byte[i18 * (i6 + 1)];
                i = DERUtils.lower_bound(prime_list, i18 << 1);
                this.indexMap = new int[i];
                i19 = 0;
                if (i19 < this.indexMap.length)
                  break label834;
                i4 = 0;
              }
            }
            else
            {
              int i15 = this.revokedCertSNs.length;
              if (i15 < 1 + (n + i6))
              {
                byte[] arrayOfByte4 = this.revokedCertSNs;
                this.revokedCertSNs = new byte[i15 * 6 / 5];
                System.arraycopy(arrayOfByte4, 0, this.revokedCertSNs, 0, i15);
              }
              this.revokedCertSNs[n] = ((byte)i6);
              System.arraycopy(arrayOfByte3, 0, this.revokedCertSNs, n + 1, i6);
              BigInteger localBigInteger = new BigInteger(arrayOfByte3);
              i16 = localBigInteger.mod(DERUtils.HexStringToBigInteger(Integer.toHexString(i))).intValue();
              if (this.indexMap[i16] != -1)
                break label848;
              this.indexMap[i16] = n;
              break label851;
            }
            while (true)
            {
              n += i6 + 1;
              this.count = (1 + this.count);
              break;
              i18 = k / m;
              this.revokedCertSNs = new byte[i18 * (i6 + 2)];
              break label630;
              this.indexMap[i19] = -1;
              i19++;
              break label651;
              int i17 = 1;
              if (i17 <= 20)
              {
                i3++;
                i16 += (i17 << 0) % i;
                if (i16 >= i)
                  i16 -= i;
                if (this.indexMap[i16] == -1)
                {
                  this.indexMap[i16] = n;
                }
                else if (!isSerialNumberExist(arrayOfByte3, this.indexMap[i16]))
                {
                  i17++;
                  if (this.indexMap[i16] != -1)
                    break label788;
                }
              }
            }
          }
          byte[] arrayOfByte1 = new byte[i6];
          paramInputStream.read(arrayOfByte1, 0, i6);
          this.pos = (i6 + this.pos);
          if ((i5 != 23) && (i5 != 24))
            break label326;
          if (i1 == 0)
          {
            String str1 = new String(arrayOfByte1);
            this.thisUpdate = DERUtils.StringToDate(str1, i5);
            i1++;
            break label326;
          }
          if (i1 != 1)
            break label326;
          String str2 = new String(arrayOfByte1);
          this.nextUpdate = DERUtils.StringToDate(str2, i5);
          i1++;
          break label326;
          break;
          j = ((Integer)localStack.pop()).intValue();
          if (this.pos == j)
            break label343;
        }
        break label54;
        if (this.indexMap[i14] != -1)
          i8++;
        i14++;
        break label81;
        byte[] arrayOfByte2 = new byte[i11];
        System.arraycopy(this.revokedCertSNs, i10 + 1, arrayOfByte2, 0, i11);
        i10 += i11 + 1;
        i13 = this.revokedCertSNs.length;
      }
      while (i10 >= i13);
    }
  }

  private boolean isSerialNumberExist(byte[] paramArrayOfByte, int paramInt)
  {
    int i = this.revokedCertSNs[paramInt];
    if (i != paramArrayOfByte.length)
      return false;
    byte[] arrayOfByte = new byte[i];
    System.arraycopy(this.revokedCertSNs, paramInt + 1, arrayOfByte, 0, i);
    int k;
    for (int j = i; ; j = k)
    {
      k = j - 1;
      if (j == 0)
        return true;
      if (paramArrayOfByte[k] != arrayOfByte[k])
        break;
    }
  }

  private int readLength(InputStream paramInputStream)
    throws IOException
  {
    int i = paramInputStream.read();
    this.pos = (1 + this.pos);
    if (i < 0)
      throw new IOException("EOF found when length expected");
    if (i == 128)
      return -1;
    if (i > 127)
    {
      int j = i & 0x7F;
      if (j > 4)
        throw new IOException("DER length more than 4 bytes");
      i = 0;
      for (int k = 0; ; k++)
      {
        if (k >= j)
        {
          if (i >= 0)
            break;
          throw new IOException("corrupted steam - negative length found");
        }
        int m = paramInputStream.read();
        this.pos = (1 + this.pos);
        if (m < 0)
          throw new IOException("EOF found reading length");
        i = m + (i << 8);
      }
    }
    return i;
  }

  public String getIssuerDNString()
  {
    if (this.issuerDNBytes == null)
      return null;
    return CertUtils.getX509NameString(this.issuerDNBytes);
  }

  public Date getNextUpdate()
  {
    return this.nextUpdate;
  }

  public Date getThisUpdate()
  {
    return this.thisUpdate;
  }

  public int getVersion()
  {
    return 1 + this.version;
  }

  public boolean isOnValidPeriod()
  {
    Date localDate = new Date();
    return (!localDate.before(this.thisUpdate)) && (!localDate.after(this.nextUpdate));
  }

  public boolean isRevoked(String paramString)
  {
    return isRevoked(DERUtils.HexStringToBigInteger(paramString));
  }

  public boolean isRevoked(BigInteger paramBigInteger)
  {
    return findSerialNumber(paramBigInteger);
  }

  public boolean isRevoked(X509Certificate paramX509Certificate)
  {
    return isRevoked(paramX509Certificate.getSerialNumber());
  }

  public int revokedCount()
  {
    return this.count;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cert.ItrusCRL
 * JD-Core Version:    0.6.2
 */